<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script>
        $(function () {
            $('[name="username"]').blur(function () {
                //获取账号
                var username = $(this).val();
                if (username==null || username==""){
                    $("#username_msg").text("账号不能为空").css("color","red");
                    return;
                }
                $.ajax({
                    url:"regist",
                    data:{"method":"checkUser","username":username},
                    dataType:"text",
                    type:"post",
                    success:function (data) {
                        if (data=="true"){
                            $("#username_msg").text("该账号已经被注册").css("color","red");
                        }else{
                            $("#username_msg").text("√").css("color","green");
                        }

                    }
                })
            })
            $('[name="password"]').blur(function () {
                var password=$(this).val();
                if (password==null || password==""){
                    $("#password_msg").text("密码不能为空").css("color","red");
                    return;
                }else{
                    $("#password_msg").text("√").css("color","green");
                }
            })
        })
    </script>

</head>
<body>
<form action="regist" method = "POST">
    <table border="1" cellspacing="0" width="500px" height="200px" align="center">
        <caption><h2>用户注册</h2></caption>
        <tr align="center">
            <td>账号：</td>
            <td>
                <input type="text" name="username">
                <span id="username_msg"></span>
            </td>
        </tr>
        <tr align="center">
            <td>密码:</td>
            <td>
                <input type="password" name="password">
                <span id="password_msg"></span>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" name="sub" value="注册">
                <input type="button" name="btn" onclick="history.back()"value="返回">

            </td>

        </tr>
    </table>
</form>
</body>
</html>
